<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Arcgis-Find Places(Swift) | 码行</title><meta name="author" content="Carl Su"><meta name="copyright" content="Carl Su"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><meta name="description" content="&#x2F;&#x2F;&#x2F;&#x2F;  ViewController.swift&#x2F;&#x2F;  ArcgissSampleFive&#x2F;&#x2F;&#x2F;&#x2F;  Created by geowin on 2020&#x2F;7&#x2F;15.&#x2F;&#x2F;  Copyright © 2020 geowin. All rights reserved.&#x2F;&#x2F;import UIKitimport ArcGISclass ViewController: UIViewController ,">
<meta property="og:type" content="article">
<meta property="og:title" content="Arcgis-Find Places(Swift)">
<meta property="og:url" content="https://devsu.top/posts/bca267fc/index.html">
<meta property="og:site_name" content="码行">
<meta property="og:description" content="&#x2F;&#x2F;&#x2F;&#x2F;  ViewController.swift&#x2F;&#x2F;  ArcgissSampleFive&#x2F;&#x2F;&#x2F;&#x2F;  Created by geowin on 2020&#x2F;7&#x2F;15.&#x2F;&#x2F;  Copyright © 2020 geowin. All rights reserved.&#x2F;&#x2F;import UIKitimport ArcGISclass ViewController: UIViewController ,">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s2.loli.net/2023/03/15/KCsFmWI24wAoLv5.jpg">
<meta property="article:published_time" content="2021-08-05T11:59:14.000Z">
<meta property="article:modified_time" content="2023-03-17T02:06:13.946Z">
<meta property="article:author" content="Carl Su">
<meta property="article:tag" content="arcgis">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s2.loli.net/2023/03/15/KCsFmWI24wAoLv5.jpg"><link rel="shortcut icon" href="https://s2.loli.net/2023/03/09/whMHdYkrKoIBnSC.png"><link rel="canonical" href="https://devsu.top/posts/bca267fc/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?6243425e2ecb037931274c4ca1db3132";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":300},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: Carl Su","link":"链接: ","source":"来源: 码行","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Arcgis-Find Places(Swift)',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2023-03-17 10:06:13'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', 'ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://s2.loli.net/2023/03/09/QrI9mgJ4XlbEPzN.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">169</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">37</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">38</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url('https://s2.loli.net/2023/03/15/KCsFmWI24wAoLv5.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="码行"><img class="site-icon" src="https://s2.loli.net/2023/03/09/whMHdYkrKoIBnSC.png"/><span class="site-name">码行</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Arcgis-Find Places(Swift)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-08-05T11:59:14.000Z" title="发表于 2021-08-05 19:59:14">2021-08-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-03-17T02:06:13.946Z" title="更新于 2023-03-17 10:06:13">2023-03-17</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/GIS/">GIS</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/GIS/Nativie/">Nativie</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">738</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>4分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Arcgis-Find Places(Swift)"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><figure class="highlight swift"><table><tr><td class="code"><pre><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">//  ViewController.swift</span></span><br><span class="line"><span class="comment">//  ArcgissSampleFive</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">//  Created by geowin on 2020/7/15.</span></span><br><span class="line"><span class="comment">//  Copyright © 2020 geowin. All rights reserved.</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> UIKit</span><br><span class="line"><span class="keyword">import</span> ArcGIS</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">ViewController</span>: <span class="title class_">UIViewController</span> ,<span class="title class_">UIPickerViewDataSource</span>,<span class="title class_">UIPickerViewDelegate</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">numberOfComponents</span>(<span class="params">in</span> <span class="params">pickerView</span>: <span class="type">UIPickerView</span>) -&gt; <span class="type">Int</span> &#123;</span><br><span class="line">        <span class="number">1</span></span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">pickerView</span>(<span class="keyword">_</span> <span class="params">pickerView</span>: <span class="type">UIPickerView</span>, <span class="params">numberOfRowsInComponent</span> <span class="params">component</span>: <span class="type">Int</span>) -&gt; <span class="type">Int</span> &#123;</span><br><span class="line">        <span class="type">Category</span>.all.count</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">pickerView</span>(<span class="keyword">_</span> <span class="params">pickerView</span>: <span class="type">UIPickerView</span>, <span class="params">titleForRow</span> <span class="params">row</span>: <span class="type">Int</span>, <span class="params">forComponent</span> <span class="params">component</span>: <span class="type">Int</span>) -&gt; <span class="type">String</span>? &#123;</span><br><span class="line">        <span class="type">Category</span>.all[row].title</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">pickerView</span>(<span class="keyword">_</span> <span class="params">pickerView</span>: <span class="type">UIPickerView</span>, <span class="params">didSelectRow</span> <span class="params">row</span>: <span class="type">Int</span>, <span class="params">inComponent</span> <span class="params">component</span>: <span class="type">Int</span>) &#123;</span><br><span class="line">        findPlaces(forCategory: <span class="type">Category</span>.all[row])</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    <span class="keyword">@IBOutlet</span> <span class="keyword">weak</span> <span class="keyword">var</span> mapView: <span class="type">AGSMapView</span>!</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">@IBOutlet</span> <span class="keyword">weak</span> <span class="keyword">var</span> categoryPicker: <span class="type">UIPickerView</span>!</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">let</span> placesOverlay <span class="operator">=</span> <span class="type">AGSGraphicsOverlay</span>()</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">let</span> locatorTask <span class="operator">=</span> <span class="type">AGSLocatorTask</span>(url: .locator)</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">var</span> currentSearch: <span class="type">AGSCancelable</span>?</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">var</span> isNavigatingObservation: <span class="type">NSKeyValueObservation</span>?</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">var</span> visibleAreaObservation: <span class="type">NSKeyValueObservation</span>?</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">override</span> <span class="keyword">func</span> <span class="title function_">viewDidLoad</span>() &#123;</span><br><span class="line">        <span class="keyword">super</span>.viewDidLoad()</span><br><span class="line">        <span class="comment">// Do any additional setup after loading the view.</span></span><br><span class="line">        initialMap()</span><br><span class="line">        <span class="comment">/// Add Observe</span></span><br><span class="line">        observeChangesInMapViewIsNavigating()</span><br><span class="line">        observeChangesInMapViewVisibleArea()</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">func</span> <span class="title function_">observeChangesInMapViewIsNavigating</span>() &#123;</span><br><span class="line">        <span class="comment">// The map view `.isNavigating` property determines if the map view&#x27;s visible area has changed.</span></span><br><span class="line">        isNavigatingObservation <span class="operator">=</span> mapView.observe(\.isNavigating) &#123; [<span class="keyword">weak</span> <span class="keyword">self</span>] (mapView, <span class="keyword">_</span>) <span class="keyword">in</span></span><br><span class="line">            <span class="comment">// Find places for a selected category when the map view stops navigating.</span></span><br><span class="line">            <span class="keyword">guard</span> <span class="operator">!</span>mapView.isNavigating <span class="keyword">else</span> &#123; <span class="keyword">return</span> &#125;</span><br><span class="line">            <span class="comment">// Update results if the map view extent has moved.</span></span><br><span class="line">            <span class="keyword">self</span><span class="operator">?</span>.findPlacesForCategoryPickerSelection()</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">func</span> <span class="title function_">observeChangesInMapViewVisibleArea</span>() &#123;</span><br><span class="line">        <span class="comment">// Use the map view `.visibleArea` property to observe when the view sets its visible area for the first time.</span></span><br><span class="line">        visibleAreaObservation <span class="operator">=</span> mapView.observe(\.visibleArea) &#123; [<span class="keyword">weak</span> <span class="keyword">self</span>] (mapView, <span class="keyword">_</span>) <span class="keyword">in</span></span><br><span class="line">            <span class="keyword">guard</span> <span class="keyword">let</span> <span class="keyword">self</span> <span class="operator">=</span> <span class="keyword">self</span> <span class="keyword">else</span> &#123; <span class="keyword">return</span> &#125;</span><br><span class="line">            <span class="comment">// When the visible area is set for the first time, kick off the first find places query.</span></span><br><span class="line">            <span class="keyword">self</span>.findPlacesForCategoryPickerSelection()</span><br><span class="line">            <span class="comment">// Nullify (thus invalidating) the visible area observation because the first find places query is performed.</span></span><br><span class="line">            <span class="keyword">self</span>.visibleAreaObservation <span class="operator">=</span> <span class="literal">nil</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// MARK:- 初始化地图</span></span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">initialMap</span>()&#123;</span><br><span class="line"><span class="comment">//        let tiledLayer = `AGSArcGISTiledLayer`(url: URL(string: &quot;http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer&quot;)!)</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">//        let map = AGSMap(basemap: AGSBasemap(baseLayer: tiledLayer))</span></span><br><span class="line"><span class="comment">//        let location = CLLocationCoordinate2D(latitude: 40.838096, longitude: 111.677914)</span></span><br><span class="line"><span class="comment">//        let center = AGSPoint(clLocationCoordinate2D: location)</span></span><br><span class="line"><span class="comment">//        map.initialViewpoint = AGSViewpoint(center: center, scale: 20000)</span></span><br><span class="line"><span class="comment">//        mapView.map = map</span></span><br><span class="line">        </span><br><span class="line">        mapView.map <span class="operator">=</span> <span class="type">AGSMap</span>(basemapType: .navigationVector, latitude: <span class="number">34.09042</span>, longitude: <span class="operator">-</span><span class="number">118.71511</span>, levelOfDetail: <span class="number">10</span>)</span><br><span class="line">        </span><br><span class="line">        mapView.graphicsOverlays.add(placesOverlay)</span><br><span class="line">        </span><br><span class="line">        mapView.touchDelegate <span class="operator">=</span> <span class="keyword">self</span></span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">addPlacesGraphics</span>(<span class="keyword">_</span> <span class="params">results</span>: [<span class="type">AGSGeocodeResult</span>],<span class="params">for</span> <span class="params">category</span>: <span class="type">Category</span>)&#123;</span><br><span class="line">        <span class="comment">// Build place marker symbol.</span></span><br><span class="line">        <span class="keyword">let</span> symbol: <span class="type">AGSSimpleMarkerSymbol</span> <span class="operator">=</span> &#123;</span><br><span class="line">            <span class="keyword">let</span> placeSymbol <span class="operator">=</span> <span class="type">AGSSimpleMarkerSymbol</span>(style: .circle, color: category.color, size: <span class="number">10.0</span>)</span><br><span class="line">            placeSymbol.outline <span class="operator">=</span> <span class="type">AGSSimpleLineSymbol</span>(style: .solid, color: .white, width: <span class="number">2</span>)</span><br><span class="line">            <span class="keyword">return</span> placeSymbol</span><br><span class="line">        &#125;()</span><br><span class="line">        <span class="comment">// Represent each place as a dot on the map.</span></span><br><span class="line">        <span class="comment">// Each graphic symbol gets the place attributes and later shows them when the user taps the graphic.</span></span><br><span class="line">        <span class="keyword">let</span> places <span class="operator">=</span> results.map &#123; (result) <span class="keyword">in</span></span><br><span class="line">            <span class="type">AGSGraphic</span>(geometry: result.displayLocation, symbol: symbol, attributes: result.attributes)</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        placesOverlay.graphics.addObjects(from: places)</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">clearPlacesGraphics</span>()&#123;</span><br><span class="line">        placesOverlay.graphics.removeAllObjects()</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">showCallout</span>(<span class="params">for</span> <span class="params">graphic</span>: <span class="type">AGSGraphic</span>)&#123;</span><br><span class="line">        mapView.callout.title <span class="operator">=</span> graphic.attributes[<span class="type">String</span>.placeName] <span class="keyword">as?</span> <span class="type">String</span> <span class="operator">??</span> <span class="string">&quot;Unknown&quot;</span></span><br><span class="line">        mapView.callout.detail <span class="operator">=</span> graphic.attributes[<span class="type">String</span>.placeAddress] <span class="keyword">as?</span> <span class="type">String</span> <span class="operator">??</span> <span class="string">&quot;no address provided&quot;</span></span><br><span class="line">        mapView.callout.show(for: graphic, tapLocation: graphic.geometry <span class="keyword">as?</span> <span class="type">AGSPoint</span>, animated: <span class="literal">true</span>)</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">hideCallout</span>()&#123;</span><br><span class="line">        <span class="keyword">if</span> mapView <span class="operator">!=</span> <span class="literal">nil</span> &#123;</span><br><span class="line">            mapView.callout.dismiss()</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">findPlaces</span>(<span class="params">forCategory</span> <span class="params">category</span>: <span class="type">Category</span>)&#123;</span><br><span class="line">        <span class="keyword">guard</span> <span class="keyword">let</span> visibleArea <span class="operator">=</span> mapView.visibleArea <span class="keyword">else</span> &#123;<span class="keyword">return</span>&#125;</span><br><span class="line">        </span><br><span class="line">        hideCallout()</span><br><span class="line">        clearPlacesGraphics()</span><br><span class="line">        </span><br><span class="line">        currentSearch<span class="operator">?</span>.cancel()</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">let</span> paramters: <span class="type">AGSGeocodeParameters</span> <span class="operator">=</span> &#123;</span><br><span class="line">            <span class="keyword">let</span> geocodeParameters <span class="operator">=</span> <span class="type">AGSGeocodeParameters</span>()</span><br><span class="line">            geocodeParameters.maxResults <span class="operator">=</span> <span class="number">25</span></span><br><span class="line">            geocodeParameters.resultAttributeNames.append(contentsOf: [. placeAddress,.placeName])</span><br><span class="line">            geocodeParameters.preferredSearchLocation <span class="operator">=</span> visibleArea.extent.center</span><br><span class="line">            geocodeParameters.categories <span class="operator">=</span> [category.title]</span><br><span class="line">            <span class="keyword">return</span> geocodeParameters</span><br><span class="line">        &#125;()</span><br><span class="line">        </span><br><span class="line">        </span><br><span class="line">        currentSearch <span class="operator">=</span> locatorTask.geocode(withSearchText: <span class="string">&quot;&quot;</span>, parameters: paramters, completion: &#123;</span><br><span class="line">            [<span class="keyword">weak</span> <span class="keyword">self</span>] (result, error) <span class="keyword">in</span></span><br><span class="line">            <span class="keyword">guard</span> <span class="keyword">let</span> <span class="keyword">self</span> <span class="operator">=</span> <span class="keyword">self</span> <span class="keyword">else</span> &#123;<span class="keyword">return</span>&#125;</span><br><span class="line">            <span class="keyword">guard</span> error <span class="operator">==</span> <span class="literal">nil</span> <span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="built_in">print</span>(<span class="string">&quot;Geocode error: &quot;</span>,error<span class="operator">!</span>.localizedDescription)</span><br><span class="line">                <span class="keyword">return</span></span><br><span class="line">            &#125;</span><br><span class="line">            </span><br><span class="line">            <span class="keyword">guard</span> <span class="keyword">let</span> result <span class="operator">=</span> result,result.count <span class="operator">&gt;</span> <span class="number">0</span> <span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="built_in">print</span>(<span class="string">&quot;No places found for category &quot;</span>,category.title)</span><br><span class="line">                <span class="keyword">return</span></span><br><span class="line">            &#125;</span><br><span class="line">            </span><br><span class="line">            <span class="keyword">self</span>.addPlacesGraphics(result, for: category)</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">func</span> <span class="title function_">findPlacesForCategoryPickerSelection</span>()&#123;</span><br><span class="line">        <span class="type">DispatchQueue</span>.main.async &#123;  [<span class="keyword">weak</span> <span class="keyword">self</span>] <span class="keyword">in</span></span><br><span class="line">            <span class="keyword">guard</span> <span class="keyword">let</span> <span class="keyword">self</span> <span class="operator">=</span> <span class="keyword">self</span> <span class="keyword">else</span> &#123;<span class="keyword">return</span>&#125;</span><br><span class="line">            <span class="keyword">let</span> categoryIndex <span class="operator">=</span> <span class="keyword">self</span>.categoryPicker.selectedRow(inComponent: <span class="number">0</span>)</span><br><span class="line">            <span class="keyword">guard</span> categoryIndex <span class="operator">&lt;</span> <span class="type">Category</span>.all.count <span class="keyword">else</span> &#123;<span class="keyword">return</span>&#125;</span><br><span class="line">            <span class="keyword">let</span> category <span class="operator">=</span> <span class="type">Category</span>.all[categoryIndex]</span><br><span class="line">            <span class="keyword">self</span>.findPlaces(forCategory: category)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">extension</span> <span class="title class_">ViewController</span>: <span class="title class_">AGSGeoViewTouchDelegate</span>&#123;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">func</span> <span class="title function_">geoView</span>(<span class="keyword">_</span> <span class="params">geoView</span>: <span class="type">AGSGeoView</span>, <span class="params">didTapAtScreenPoint</span> <span class="params">screenPoint</span>: <span class="type">CGPoint</span>, <span class="params">mapPoint</span>: <span class="type">AGSPoint</span>) &#123;</span><br><span class="line">        hideCallout()</span><br><span class="line">        </span><br><span class="line">        mapView.identify(placesOverlay, screenPoint: screenPoint, tolerance: <span class="number">10</span>, returnPopupsOnly: <span class="literal">false</span>, maximumResults: <span class="number">1</span>) &#123; [<span class="keyword">weak</span> <span class="keyword">self</span>](result) <span class="keyword">in</span></span><br><span class="line">            <span class="keyword">guard</span> <span class="keyword">let</span> <span class="keyword">self</span> <span class="operator">=</span> <span class="keyword">self</span> <span class="keyword">else</span> &#123; <span class="keyword">return</span> &#125;</span><br><span class="line">            <span class="keyword">if</span> <span class="keyword">let</span> error <span class="operator">=</span> result.error&#123;</span><br><span class="line">                <span class="built_in">print</span>(error)</span><br><span class="line">                <span class="keyword">return</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> <span class="keyword">let</span> graphic <span class="operator">=</span> result.graphics.first&#123;</span><br><span class="line">                <span class="keyword">self</span>.showCallout(for: graphic)</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://devsu.top">Carl Su</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://devsu.top/posts/bca267fc/">https://devsu.top/posts/bca267fc/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://devsu.top" target="_blank">码行</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/arcgis/">arcgis</a></div><div class="post_share"><div class="social-share" data-image="https://s2.loli.net/2023/03/15/KCsFmWI24wAoLv5.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/a9e2c3a3/" title="ViewModel和ViewModelProvider"><img class="cover" src="https://img2.baidu.com/it/u=3327510359,3066345512&amp;fm=253&amp;fmt=auto&amp;app=138&amp;f=PNG?w=1086&amp;h=500" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">ViewModel和ViewModelProvider</div></div></a></div><div class="next-post pull-right"><a href="/posts/f21d2a2b/" title="NavigationLink隐藏右侧小箭头"><img class="cover" src="https://s2.loli.net/2023/03/15/Le4RdOMASnT5tha.webp" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">NavigationLink隐藏右侧小箭头</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/e568ea1/" title="Arcgis-Search for an address"><img class="cover" src="https://img0.baidu.com/it/u=3455713378,1116618819&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-05</div><div class="title">Arcgis-Search for an address</div></div></a></div><div><a href="/posts/704a878a/" title="Arcgis offline map(Swift)"><img class="cover" src="https://s2.loli.net/2023/03/17/xZ8Tt5pBfanhJr4.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-05</div><div class="title">Arcgis offline map(Swift)</div></div></a></div><div><a href="/posts/97fdcddb/" title="Arcgis for Android 100.10.0(一)：开发环境配置"><img class="cover" src="https://s2.loli.net/2023/03/17/wN8xPqOafKW4Fdh.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-05</div><div class="title">Arcgis for Android 100.10.0(一)：开发环境配置</div></div></a></div><div><a href="/posts/e6f64ca3/" title="Arcgis Runtime API for Android 100.13 (一)环境配置"><img class="cover" src="https://hbimg.b0.upaiyun.com/364083e61dca34f73f92336e702f7fe9a6f604e01e7ad-omikhi_fw658" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-05</div><div class="title">Arcgis Runtime API for Android 100.13 (一)环境配置</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div><div id="comment-switch"><span class="first-comment">Valine</span><span class="switch-btn"></span><span class="second-comment">Disqus</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div><div><div id="disqus_thread"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://s2.loli.net/2023/03/09/QrI9mgJ4XlbEPzN.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Carl Su</div><div class="author-info__description">纸上得来终觉浅，绝知此事要躬行。</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">169</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">37</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">38</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/winstone-su" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:winstone.su@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">学习如逆水行舟，不进则退。</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/7098ebd6/" title="2023-03-30-Windows下PowerShell自定义函数"><img src="https://s2.loli.net/2023/03/30/6ilJQwW3T2e89xy.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="2023-03-30-Windows下PowerShell自定义函数"/></a><div class="content"><a class="title" href="/posts/7098ebd6/" title="2023-03-30-Windows下PowerShell自定义函数">2023-03-30-Windows下PowerShell自定义函数</a><time datetime="2023-03-30T01:57:31.000Z" title="发表于 2023-03-30 09:57:31">2023-03-30</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/e6af74ea/" title="2023-03-30-Funny Github">2023-03-30-Funny Github</a><time datetime="2023-03-30T01:12:25.000Z" title="发表于 2023-03-30 09:12:25">2023-03-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/7028d55e/" title="2023-03-29-CE修改器加速百度网盘下载"><img src="https://img1.mydrivers.com/img/20210916/ecbb517f-6cd5-438f-9efc-98e9973eece3.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="2023-03-29-CE修改器加速百度网盘下载"/></a><div class="content"><a class="title" href="/posts/7028d55e/" title="2023-03-29-CE修改器加速百度网盘下载">2023-03-29-CE修改器加速百度网盘下载</a><time datetime="2023-03-29T01:48:38.000Z" title="发表于 2023-03-29 09:48:38">2023-03-29</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/bf1f0a14/" title="2023-03-27-Hilt基本用法">2023-03-27-Hilt基本用法</a><time datetime="2023-03-27T09:14:16.000Z" title="发表于 2023-03-27 17:14:16">2023-03-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/6f434e78/" title="2023-03-23-CentOS新建定时任务"><img src="https://s2.loli.net/2023/03/23/KLmkEbpJArO4z1H.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="2023-03-23-CentOS新建定时任务"/></a><div class="content"><a class="title" href="/posts/6f434e78/" title="2023-03-23-CentOS新建定时任务">2023-03-23-CentOS新建定时任务</a><time datetime="2023-03-23T03:08:39.000Z" title="发表于 2023-03-23 11:08:39">2023-03-23</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2018 - 2023 By Carl Su</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">学无止境</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="chat_btn" type="button" title="聊天"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: '',
      appKey: '',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script><script>function loadDisqus () {
  var disqus_config = function () {
    this.page.url = 'https://devsu.top/posts/bca267fc/'
    this.page.identifier = '/posts/bca267fc/'
    this.page.title = 'Arcgis-Find Places(Swift)'
  };

  window.disqusReset = () => {
    DISQUS.reset({
      reload: true,
      config: disqus_config
    })
  }

  if (window.DISQUS) disqusReset()
  else {
    (function() { 
      var d = document, s = d.createElement('script');
      s.src = 'https://.disqus.com/embed.js';
      s.setAttribute('data-timestamp', +new Date());
      (d.head || d.body).appendChild(s);
    })();
  }

  document.getElementById('darkmode').addEventListener('click', () => {
    setTimeout(() => window.disqusReset(), 200)
  })
}

if ('Valine' === 'Disqus' || !true) {
  if (true) btf.loadComment(document.getElementById('disqus_thread'), loadDisqus)
  else loadDisqus()
} else {
  function loadOtherComment () {
    loadDisqus()
  }
}
</script></div><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></body></html>